<?php
/**
 * I-Cafe framework
 * 
 * @category CF
 * @package CF_Db
 * @link http://www.i-cafe.org
 * @license http://www.i-cafe.org/license
 * @version 04-04-2010
 * @author tcl_java@yahoo.com
 */

/**
 * A class hander query transaction
 * <code>
 * 	$queries = array(
 * 		"INSERT INTO products(`name`, `price`) VALUES ('Product 1', 300)",
 * 		"DELETE FROM `products` WHERE id IN(1,2,3)"
 * 	);
 * 	
 * 	$db = CF_Db::getInstance();
 * 	$db->setConnection($connection);
 * 	$db->query($queries);
 * </code>
 */
class CF_Db_Transaction
{
	/**
	 * Start transaction
	 * @return void
	 */
	public static function start()
	{
		CF_Db::getInstance()->query("SET AUTOCOMMIT=0");
		CF_Db::getInstance()->query("START TRANSACTION");
	}
	
	/**
	 * Commit transaction
	 * @return void
	 */
	public static function commit()
	{
		CF_Db::getInstance()->query("COMMIT");
		CF_Db::getInstance()->query("SET AUTOCOMMIT=1");
	}
	
	/**
	 * Rollback transaction
	 * @return 
	 */
	public static function rollback()
	{
		CF_Db::getInstance()->query("ROLLBACK");
		CF_Db::getInstance()->query("SET AUTOCOMMIT=1");
	}
}
